Repository navigation
Start new tasks as soon as a running task finishes - #622
Merged
Merged
Conversation
When every slot was busy, the worker slept for minimum_check_interval before it looked for finished tasks. Throughput was therefore capped at concurrency / minimum_check_interval: 4 tasks/s per slot for Worker() (250 ms) and 10 for `docket worker` (100 ms), however fast tasks ran. The worker now waits on its active tasks with FIRST_COMPLETED, using the same interval as a timeout. docket-rs already waits this way with JoinSet::join_next(). test_waiter_woken_before_its_safeguard_exists_cancels_the_safeguard polled for the woken waiter's "queued" state. The worker now claims and finishes the woken task before the poll runs, so the test checks that the state has left "scheduled". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
chrisguidry
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem. When every slot was busy, the worker slept for
minimum_check_intervalbefore it looked for finished tasks. That capped a worker atconcurrency / minimum_check_intervaltasks per second, however fast the tasks ran: 4 tasks/s per slot forWorker()(250 ms) and 10 fordocket worker(100 ms).The fix. The worker waits on its active tasks with
asyncio.wait(..., return_when=FIRST_COMPLETED), usingminimum_check_intervalas the timeout. A slot that frees up takes new work at once. docket-rs already waits this way withJoinSet::join_next().One
Worker()process drained pre-enqueued no-op tasks from Redis 8.10 on the same machine, without hiredis. Each side ran three times with the same task count:Main's numbers equal
concurrency × 4in every run, which is the cap the sleep sets. The rate is the task count divided by the time from the worker starting to the last task finishing. Over a network, each task's two Redis round trips cost more, so the branch's numbers will be lower; main's cap stays the same.test_waiter_woken_before_its_safeguard_exists_cancels_the_safeguardpolled for the woken waiter'squeuedstate. The worker now claims and finishes the woken task before that poll runs, so the test checks that the state has leftscheduled.Rollout caveats
watch: Redis command rate from workers. A busy worker now reads the stream each time a task finishes, where it used to read once per interval, so XREADGROUP calls can rise with task completionsBenchmark script
Run it with a Redis on port 6390, for example
python bench.py --n 1000 --concurrency 10.Session context
This came out of benchmarking for throughput gains that need no API change. The same benchmark found that redis-py 7 and later cap the connection pool at 100 and raise
MaxConnectionsErrorwhen it is full. A worker withconcurrencynear 100 then stops polling, and the messages it read stay pending until the redelivery timeout. That fix is in a separate branch. hiredis added about 40% on top of this change in the same benchmark.🤖 Generated with Claude Code